package com.tianxiang.model;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.tianxiang.action.ImageAction;

public class ImageResult implements Result {

	private static final long serialVersionUID = 1L;

	@Override
	public void execute(ActionInvocation ai) throws Exception {
		ImageAction action = (ImageAction)ai.getAction();
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Cash", "no cash");
		response.setContentType(action.getContentType());
		response.setContentLength(action.getContentLength());
		response.getOutputStream().write(action.getImageBytes());
		response.getOutputStream().flush();
	}

}
